home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char rcsid[] = "$Header: check.c,v 1.4 87/02/12 13:21:04 schoch Exp $";
- #endif
-
- /* check.c */
- #include "externs.h"
-
- moveintocheck (from, to)
- int from, to;
- {
- int victim, intocheck;
- u_char color;
- LIST check ();
-
- color = whose [from]; /* make move on board */
- victim = findvictim (from, to);
- if (victim)
- whose [victim] = EMPTY;
- whose [to] = color;
- whose [from] = EMPTY;
- if (occupant [from] == KING)
- kingloc [color] = to;
- intocheck = (check (color) != NIL); /* see if now in check */
- if (occupant [from] == KING) /* restore board position */
- kingloc [color] = from;
- whose [from] = color;
- whose [to] = EMPTY;
- if (victim)
- whose [victim] = 1 - color;
- return intocheck;
- }
-
- LIST
- check (color)
- u_char color;
- {
- LIST l, checkdirs, lmember (), linsert ();
- int direction, spot, dist, side;
-
- checkdirs = NIL;
- l = dirlist [QUEEN];
- while (l != NIL) {
- direction = l->i;
- l = l->n;
- spot = kingloc [color];
- for (dist = 1; TRUE; dist++) {
- spot += direction;
- if (spot < 0 || spot > 99)
- continue;
- if ((whose [spot] == 1 - color)
- && (lmember (-direction, dirlist [occupant [spot]])
- && !(occupant [spot] == KING && dist > 1)))
- checkdirs = linsert (checkdirs, direction);
- if (whose [spot] != EMPTY)
- break;
- }
- }
- l = dirlist [KNIGHT];
- while (l != NIL) {
- direction = l->i;
- l = l->n;
- spot = kingloc [color] + direction;
- if (spot < 0 || spot > 99)
- continue;
- if (whose [spot] == 1 - color && occupant [spot] == KNIGHT)
- checkdirs = linsert (checkdirs, direction);
- }
- for (side = -1; side <= 1; side += 2) {
- spot = kingloc [color] + pawndir [color] + side;
- if (spot < 0 || spot > 99)
- continue;
- if (whose [spot] == 1 - color && occupant [spot] == PAWN)
- checkdirs = linsert(checkdirs, pawndir [color] + side);
- }
-
- return checkdirs;
- }
-